package admin

import database "hft/Database"

type Route struct {
	database.Base
	PID       uint     `json:"pid,omitempty" gorm:"foreignKey:PID;references:ID;constraint:OnDelete:CASCADE,OnUpdate:NO ACTION;default:null"`
	Name      string   `json:"name,omitempty" gorm:"not null;type:varchar(30);uniqueIndex"`
	Path      string   `json:"path,omitempty" gorm:"not null;type:varchar(255);size:255;uniqueIndex"`
	Component string   `json:"component"`
	Redirect  string   `json:"redirect,omitempty"`
	Meta      *Meta    `json:"meta,omitempty" gorm:"foreignKey:RouteId;constraint:OnDelete:CASCADE,OnUpdate:CASCADE"`
	Children  []*Route `json:"children" gorm:"foreignKey:PID;constraint:OnDelete:CASCADE,OnUpdate:NO ACTION;default:null"`
	Apis      []*Api   `json:"apis" gorm:"foreignKey:RouteID;references:ID;constraint:OnDelete:CASCADE"`
	Roles     []*Role  `json:"roles,omitempty" gorm:"many2many:_routes_roles;foreignKey:ID;JoinForeignKey:RouteId;references:ID;JoinReferences:RoleId;constraint:OnDelete:CASCADE,OnUpdate:NO ACTION"`
}

func (Route) TableName() string {
	return database.TableNameFormat("routes")
}
